package com.mobilebsc.httpclient.callback;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

import com.mobilebsc.datatype.StrategicGoal;

public class StrategicGoalReferencedByX_HttpResponseHandler extends
		StrategicGoalHttpResponseHandler {

	private static final String TAG = "StrategicGoalReferencedByX_HttpResponseHandler";

	public StrategicGoalReferencedByX_HttpResponseHandler(
			IAsyncTaskCompleteListener<List<StrategicGoal>> callback) {
		super(callback);
	}

	@Override
	public void onSuccess(JSONArray referencedStrategicGoals) {

		Log.i(TAG,
				"onSuccess0 = JSON length " + referencedStrategicGoals.length()
						+ ", JSON string "
						+ referencedStrategicGoals.toString());

		strategicGoalsList = new ArrayList<StrategicGoal>();
		JSONObject strategicGoalJSON = new JSONObject();

		if (referencedStrategicGoals.length() == 0) {
			strategicGoalsList.add(new StrategicGoal());
		} else {
			for (int i = 0; i < referencedStrategicGoals.length(); i++) {
				try {
					strategicGoalJSON = referencedStrategicGoals.getJSONObject(
							i).optJSONObject("referencedgoal");
					StrategicGoal strategicGoal = new StrategicGoal(
							strategicGoalJSON);
					strategicGoalsList.add(strategicGoal);
				} catch (JSONException e) {
					Log.e(TAG, "onSuccess = " + e.toString());
				}
			}
		}
	}
}